package com.wooming.studentinfosystem.controller;

import com.wooming.studentinfosystem.service.impl.StudentDeleteService;
import com.wooming.studentinfosystem.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Controller层: 学生信息删除
 *
 * @author Wooming
 */
@RestController
@RequestMapping("/api/students")
public class StudentDeleteController {

    @Autowired
    private StudentDeleteService studentDeleteService;

    @DeleteMapping("/{id}")
    public Result<?> deleteStudent(@PathVariable String id) {
        // 判断学生是否存在
        if (!studentDeleteService.isStudentIdExists(id)) {
            return Result.error(404, "学生不存在");
        }

        // 执行删除操作
        studentDeleteService.deleteStudent(id);
        return Result.success(null);
    }
}
